﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kiiro.ExceptionManagement
{
    public class KiiroProvisionerException : Microsoft.SharePoint.SPException
    {

        public enum ErrorType : byte
        {
            PortalLimitReached = 0,
            ProjectLimitReached = 1,

            Other = 9
        }

        #region Properties

        private ErrorType type = ErrorType.Other;
        public ErrorType Type
        {
            get { return this.type; }
            set { this.type = value; }
        }

        private Exception unhandledException = null;
        public Exception UnhandledException
        {
            get { return this.unhandledException; }
            set { this.unhandledException = value; }
        }

        #endregion // Properties

        #region Constructors

        private KiiroProvisionerException ( ) { }

        public KiiroProvisionerException ( ErrorType errorType )
        {
            this.Type = errorType;
        }

        public KiiroProvisionerException(Exception ex)
        {
            this.Type = ErrorType.Other;
            this.UnhandledException = ex;
        }

        #endregion // Constructors

        #region Overridden Properties

        public override string Message
        {
            get
            {
                string message = default ( string );

                switch ( this.Type )
                {
                    case ErrorType.PortalLimitReached:
                        message = "Kiiro Instance limit reached, please acquire a new license key to continue or remove an existing Portal Site";
                        break;

                    case ErrorType.ProjectLimitReached:
                        message = "Active Projects Limit reached. Cannot create more Projects.";
                        break;

                    case ErrorType.Other:
                        message = "An unexpected error occured.\r\n" + this.UnhandledException.Message;
                        break;

                    default:
                        message = "An unexpected error occured.\r\n" + base.Message;
                        break;
                }

                return message;
            }
        }

        public override string StackTrace
        {
            get { return this.Type == ErrorType.Other ? this.UnhandledException.StackTrace : base.StackTrace; }
        }

        public override System.Collections.IDictionary Data
        {
            get { return this.Type == ErrorType.Other ? this.UnhandledException.Data : base.Data; }
        }

        public override string Source
        {
            get { return this.Type == ErrorType.Other ? this.UnhandledException.Source : base.Source; }
            set { base.Source = value; }
        }

        public override string HelpLink
        {
            get { return this.Type == ErrorType.Other ? this.UnhandledException.HelpLink : base.HelpLink; }
            set { base.HelpLink = value; }
        }

        #endregion // Overridden Properties

    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.ExceptionManagement/KiiroProvisionerException.cs $
 * 
 * 3     17/08/09 10:45a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/